package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.ClienteFisica;

public class ClienteFisicaDAO {
	
private final Connection connection;
	
	public ClienteFisicaDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(ClienteFisica clientefisica){
		String sql = "insert into clientefisica (idcliente, datanascimento, codtipoprofissao, " +
													"codtiposexo, numrg, descorgaoexprg, iduforgexprg, dataemissaorg) values (?, ?, ?, ?, ?, ?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setLong(1, clientefisica.getIdcliente());
			stmt.setDate(2, clientefisica.getDatanascimento());
			stmt.setInt(3, clientefisica.getCodtipoprofissao());
			stmt.setInt(4, clientefisica.getCodtiposexo());
			stmt.setString(5, clientefisica.getNumrg());
			stmt.setString(6, clientefisica.getDescorgaoexprg());
			stmt.setInt(7, clientefisica.getIduforgexprg());
			stmt.setDate(8, clientefisica.getDataemissaorg());
			
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
